import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from project_utils.get_ac_mappings import mappings
from config import *
from concat_sql.ac_column_mapping import insert_ac_mapping
from concat_sql.ac_material import get_material
import datetime
import multiprocessing

def get_result(future):
    print(future.result())


if __name__ == '__main__':

    material_model = get_material(material_table)
    # 历史所有日期
    begin = datetime.date(AC_START_YEAR, AC_START_MONTH, AC_START_DAY)
    end = datetime.date(AC_END_YEAR, AC_END_MONTH, AC_END_DAY)
    date_list = [(begin + datetime.timedelta(days=i)).strftime("%Y-%m-%d") for i in range((end - begin).days+1)]
    results = []
    pool = multiprocessing.Pool(processes=80)
    for date in date_list:
        if date < AC_LINE_TIME:
            mappings_ls= mappings(history=True)
        else:
            mappings_ls = mappings(history=False)
        for i in material_model[0]:
            insert_ac_mapping(mappings_ls, date, i)
            result = pool.apply_async(insert_ac_mapping, (mappings_ls, date, i))
            results.append(result)
    pool.close()
    pool.join()




